package com.eqs.enterprisequestionnaire.controller;

import com.eqs.enterprisequestionnaire.model.pojo.Role;
import com.eqs.enterprisequestionnaire.result.R;
import com.eqs.enterprisequestionnaire.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    RoleService roleService;

    //添加新角色（权限等级，rightLevel=1是员工 2是领导 3可以是工信部）
    @PostMapping("")
    public R<String> addRole(@RequestBody Role role){
        roleService.save(role);
        return R.success("成功添加角色");
    }

    //得到角色，id、名称、权限等级
    @GetMapping("")
    public R<Role> getRole(Integer roleId){
        return R.success(roleService.getById(roleId));
    }
    //删除角色
    @DeleteMapping("/delete/{id}")
    public R<String> deleteRole(Integer id){
        if(roleService.removeById(id)){
            return R.success("删除成功");
        }
        else
            return R.error("删除失败");
    }
}
